package com.taoxi.shops.controller;

import com.taoxi.common.annotation.Anonymous;
import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.shops.domain.Factory;
import com.taoxi.shops.service.IFactoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 加工厂管理Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@Api(tags = "加工厂管理Controller")
@RestController
@RequestMapping("/shops/factory")
public class FactoryController extends BaseController {
    @Autowired
    private IFactoryService factoryService;

    /**
     * 查询加工厂管理列表
     */
    @ApiOperation("查询加工厂管理列表")
    @PreAuthorize("@ss.hasPermi('shops:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(Factory factory) {
        startPage();
        List<Factory> list = factoryService.selectFactoryList(factory);
        return getDataTable(list);
    }

    /**
     * 导出加工厂管理列表
     */
    @ApiOperation("导出加工厂管理列表")
    @PreAuthorize("@ss.hasPermi('shops:factory:export')")
    @Log(title = "加工厂管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Factory factory) {
        List<Factory> list = factoryService.selectFactoryList(factory);
        ExcelUtil<Factory> util = new ExcelUtil<Factory>(Factory.class);
        util.exportExcel(response, list, "加工厂管理数据");
    }

    /**
     * 获取加工厂管理详细信息
     */
    @ApiOperation("获取加工厂管理详细信息")
    @PreAuthorize("@ss.hasPermi('shops:factory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(factoryService.selectFactoryById(id));
    }

    /**
     * 新增加工厂管理
     */
    @ApiOperation("新增加工厂管理")
    @PreAuthorize("@ss.hasPermi('shops:factory:add')")
    @Log(title = "加工厂管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Factory factory) {
        return toAjax(factoryService.insertFactory(factory));
    }

    /**
     * 修改加工厂管理
     */
    @ApiOperation("修改加工厂管理")
    @PreAuthorize("@ss.hasPermi('shops:factory:edit')")
    @Log(title = "加工厂管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Factory factory) {
        return toAjax(factoryService.updateFactory(factory));
    }

    /**
     * 删除加工厂管理
     */
    @ApiOperation("删除加工厂管理")
    @PreAuthorize("@ss.hasPermi('shops:factory:remove')")
    @Log(title = "加工厂管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(factoryService.deleteFactoryByIds(ids));
    }

    /**
     * 查询加工厂销量排序
     */
    @Anonymous
    @ApiOperation("加工厂销量排序")
    @GetMapping("/getSalesSort")
    public TableDataInfo getSalesSort(Factory factory) {
        startPage();
        List<Factory> list = factoryService.getSalesSort(factory);
        return getDataTable(list);
    }

}
